/*
 * @Author: qianmingtian
 * @Date: 2020-07-18 15:42:32
 * @LastEditors: qianmingtian
 * @LastEditTime: 2020-07-18 16:04:34
 * @FilePath: \qianmingtian.github.io\code\java\MultiThread\TimerTest.java
 */
package MultiThread;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

/**
 * 定时器： Timer定时器
 */
class MyTimer extends TimerTask {
    int i = 0;

    @Override
    public void run() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String time = sdf.format(new Date());
        System.out.println(time + "----" + (i++));

    }

}

public class TimerTest {
    public static void main(String[] args) throws ParseException {
        Timer t = new Timer();

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date firstTime = sdf.parse("2020-7-18 16:04:59");

        t.schedule(new MyTimer(), firstTime, 1000 * 10);
        // t.schedule(new MyTimer(), new Date(), 1000 * 10);
    }

}